package com.ghh.app.monsterrush.monsters.state;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.ghh.app.monsterrush.MonsterActor;
import com.ghh.app.monsterrush.StateAction;

public class WalkingState implements StateAction {
	private float			stateTime	= 0f;
	private MonsterActor	monster;
	private TextureRegion	textureRegion;
	private Animation		animation;

	public WalkingState(MonsterActor monster, Texture texture) {
		this.monster = monster;
		this.textureRegion = new TextureRegion(texture);
	}

	public WalkingState(MonsterActor monster, TextureRegion[] frames, float frameDuration) {
		this.monster = monster;
		this.animation = new Animation(frameDuration, frames);
	}

	@Override
	public void start() {
		stateTime = 0f;
	}

	@Override
	public void act(float deltaTime) {
		stateTime += deltaTime;
		monster.walk();
	}

	@Override
	public void draw(SpriteBatch batch) {
		if (textureRegion != null) {
			monster.drawFrame(batch, textureRegion);
		} else {
			monster.drawFrame(batch, animation.getKeyFrame(stateTime, true));
		}
	}
}
